<template>
  <div class="import-contain">
    <el-card>
      <h2 class="titleImport">员工导入</h2>
      <p class="contents">
        每次导入仅可添加1000名员工,姓名、手机、入职时间、聘用形式为必填项
      </p>
      <excelImport class="import-contain" :on-success="onSuccess" />
    </el-card>
  </div>
</template>

<script>
import { formatDate } from '../../utils/index'
import excelImport from '../../components/UploadExcel'
import { importEmployees } from '@/api/employees'
export default {
  components: {
    excelImport
  },
  methods: {
    async onSuccess(data) {
      console.log('data.results', data.results)
      const arr = data.results.map(v => {
        v.correctionTime = formatDate(v.correctionTime, '/')
        v.timeOfEntry = formatDate(v.timeOfEntry, '/')
        return v
      })
      console.log(arr)
      await importEmployees(arr)
      this.$router.push({ path: '/employees' })
      this.$message.success('批量导入成功')
    }
  }
}
</script>

<style lang="scss">
.import-contain {
  padding: 40px;
  .titleImport {
    text-align: center;
  }
  .contents {
    color: orange;
    padding: 5px;
    background-color: #fdf6ec;
  }
}
</style>
